﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Entity;
using System.Web;
using System.Web.Mvc;
using XStudio.XCRF.Data.Business;
using XStudio.XCRF.Data.Business.Permissions;
using XStudio.XCRF.Data.Entities;
using XStudio.XCRF.Data.Enums;

namespace XStudio.XCRF.Web.Controllers
{
    [DefaultPermission(PermissionType.Allow)]
    public class LabCheckStdController : BaseController
    {
        public ActionResult LabCheckStdAdd(Guid hospitalID, byte gender)
        {
            Hospital hospital = DataContext.Hospitals.Find(hospitalID);
            LabCheckStd labCheckStd = new LabCheckStd
            {
                HospitalID = hospitalID,
                Hospital = hospital,
                Gender = gender
            };
            return View(labCheckStd);
        }

        [HttpPost]
        public ActionResult _LabCheckStdAdd(LabCheckStd labCheckStd)
        {
            try
            {
                DataContext.LabCheckStds.Add(labCheckStd);
                DataContext.SaveChanges();
                return Json(new { ID = labCheckStd.HospitalID });
            }
            catch
            {
                return Json(null);
            }
        }

        public ActionResult LabCheckStdEdit(Guid labCheckStdID)
        {
            LabCheckStd lab = ((IQueryable<LabCheckStd>)DataContext.LabCheckStds).Find(labCheckStdID);
            return View(lab);
        }

        [HttpPost]
        public ActionResult _LabCheckStdEdit(LabCheckStd labCheckStd)
        {
            try
            {
                LabCheckStd l = DataContext.LabCheckStds.Find(labCheckStd.ID);
                l.ESRmax = labCheckStd.ESRmax;
                l.ESRmin = labCheckStd.ESRmin;

                l.RBCmax = labCheckStd.RBCmax;
                l.RBCmin = labCheckStd.RBCmin;
                l.PLTmax = labCheckStd.PLTmax;
                l.PLTmin = labCheckStd.PLTmin;
                l.Hbmax = labCheckStd.Hbmax;
                l.Hbmin = labCheckStd.Hbmin;
                l.WBCmax = labCheckStd.WBCmax;
                l.WBCmin = labCheckStd.WBCmin;
                l.NEUmax = labCheckStd.NEUmax;
                l.NEUmin = labCheckStd.NEUmin;
                l.LYMmax = labCheckStd.LYMmax;
                l.LYMmin = labCheckStd.LYMmin;
                l.MNCmax = labCheckStd.MNCmax;
                l.MNCmin = labCheckStd.MNCmin;

                l.CEAmax = labCheckStd.CEAmax;
                l.CEAmin = labCheckStd.CEAmin;
                l.CA50max = labCheckStd.CA50max;
                l.CA50min = labCheckStd.CA50min;
                l.CA199max = labCheckStd.CA199max;
                l.CA242min = labCheckStd.CA242min;
                l.CA724max = labCheckStd.CA724max;
                l.CA724min = labCheckStd.CA724min;

                l.PROmax = labCheckStd.PROmax;
                l.PROmin = labCheckStd.PROmin;
                l.GLUmax = labCheckStd.GLUmax;
                l.GLUmin = labCheckStd.GLUmin;
                l.BLDmax = labCheckStd.BLDmax;
                l.BLDmin = labCheckStd.BLDmin;
                l.LEUmax = labCheckStd.LEUmax;
                l.LEUmin = labCheckStd.LEUmin;

                l.BXBmax = labCheckStd.BXBmax;
                l.BXBmin = labCheckStd.BXBmin;
                l.FBmax = labCheckStd.FBmax;
                l.FBmin = labCheckStd.FBmin;

                l.ASTmax = labCheckStd.ASTmax;
                l.ASTmin = labCheckStd.ASTmin;
                l.ALTmax = labCheckStd.ALTmax;
                l.ALTmin = labCheckStd.ALTmin;
                l.BUNmax = labCheckStd.BUNmax;
                l.BUNmin = labCheckStd.BUNmin;
                l.SCrmax = labCheckStd.SCrmax;
                l.SCrmin = labCheckStd.SCrmin;
                l.ZDHSmax = labCheckStd.ZDHSmax;
                l.ZDHSmin = labCheckStd.ZDHSmin;
                l.JHDHSmax = labCheckStd.JHDHSmax;
                l.JHDHSmin = labCheckStd.JHDHSmin;
                l.BDBmax = labCheckStd.BDBmax;
                l.BDBmin = labCheckStd.BDBmin;
                l.JXLSMmax = labCheckStd.JXLSMmax;
                l.JXLSMmin = labCheckStd.JXLSMmin;
                l.GAXZTMmax = labCheckStd.GAXZTMmax;
                l.GAXZTMmin = labCheckStd.GAXZTMmin;
                l.ZDGCmax = labCheckStd.ZDGCmax;
                l.ZDGCmin = labCheckStd.ZDGCmin;
                l.NSmax = labCheckStd.NSmax;
                l.NSmin = labCheckStd.NSmin;

                l.NKmax = labCheckStd.NKmax;
                l.NKmin = labCheckStd.NKmin;
                l.CD3max = labCheckStd.CD3max;
                l.CD3min = labCheckStd.CD3min;
                l.CD4_CD8max = labCheckStd.CD4_CD8max;
                l.CD4_CD8min = labCheckStd.CD4_CD8min;
                l.CD4max = labCheckStd.CD4max;
                l.CD4min = labCheckStd.CD4min;
                l.CD8max = labCheckStd.CD8max;
                l.CD8min = labCheckStd.CD8min;
                DataContext.SaveChanges();
                return Json(new { ID = l.HospitalID });
            }
            catch
            {
                return Json(null);
            }
        }

        public ActionResult LabCheckStdDetail(Guid hospitalID)
        {
            Hospital hospital = ((IQueryable<Hospital>)DataContext.Hospitals
                    .Include(h => h.LabCheckStds))
                .Find(hospitalID);
            return View(hospital);
        }

        public ActionResult LabCheckStdDetailInfo(Guid labCheckStdID)
        {
            LabCheckStd labCheckStd = ((IQueryable<LabCheckStd>)DataContext.LabCheckStds)
                .Find(labCheckStdID);
            return PartialView(labCheckStd);
        }
    }
}
